<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/meta.jsp" %>
<%@ include file="/common/import.jsp" %>
<!DOCTYPE html>
<html>
<head>
	<title>黑名单冻结列表</title>
	
	<script type="text/javascript">
		$(function(){
			
			 
			//获取黑名单冻结列表,解冻只需要将IP设为空
			$('#brList').datagrid({
				title:'黑名单冻结列表',
				iconCls:'icon-ok',
				url:'${ctx}/passport/black/list!data.action',
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[15,20,30,50],
				idField:'brId',
				columns:[[
					{field:'brAccount',title:'登录账户',width:60,sortable:true},
					{field:'brIpaddress',title:'冻结IP地址',width:80,sortable:true},
					{field:'brRemark',title:'冻结备注',width:150,sortable:true},
					{field:'brCreatetime',title:'冻结创建时间',width:80,sortable:true},
					{field:'brRelievetime',title:'解冻时间',width:80,sortable:true},
					{field:'userEname',title:'解冻人',width:60,sortable:true}
				]],
				toolbar:[{
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						saveBr();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteBr();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editBr();
					}
				},'-',{
					text:'刷新',
					iconCls:'icon-reload',
					handler:function(){
						brReload();
					}
				}
				]
			});		
		});
		
		// 进入增加页面
		function saveBr(){
			$('#saveFrame').html('');			
			var url = '${ctx}/passport/black/black-save.action';				
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		// 进入修改页面
		function editBr(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/passport/black/edit.action?sysId='+node.brId;
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}

		// 判断是否选中一条记录
		function getSelected(){
			var selected = $('#brList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
				
		//清空查询数据库,并重新查询
		function clearSearch(){					
		    $('#brCreatetime').val('');
		    searchList(); 
		 }
		// 点击取消按钮，关闭添加窗口
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		// 刷新列表
		function brReload(){
			$('#brList').datagrid('reload');
		}
		
		//查询
		function searchList(){			
	    	var queryParams = $('#brList').datagrid('options').queryParams;	    
	       	var opt = $('#brList').datagrid('getPager').data("pagination").options;  
	        $('#brList').datagrid('options').pageNumber=1;
	        queryParams["brCreatetime"] = $('#brCreatetime').val();
	        $('#brList').datagrid('reload');
	        var page = $('#brList').datagrid('getPager');
			page.pagination({pageNumber:1,pageSize:opt.pageSize});
		 }
		 
		 //删除，物理删除
		function deleteBr(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.brIpaddress+'</font> ?',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/passport/black/del.action?sysId="+node.brId+"&userEname="+node.brAccount,
							dataType: "json",
							success: function(data){
								var result = data;//jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info');	
								    var rowIndex = $('#brList').datagrid('getRowIndex',node);								
								    $('#brList').datagrid('deleteRow', rowIndex);	
								    brReload();
	    						}else if(result.flag=='H'){
	    							$.messager.alert('结果', result.msg, 'info');	
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							},
							error:function(messg)  { 
					       	    $.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
					       } 
						});
		          	}
		       });		             		
		    }	
		}
	</script>
</head>
<body>
	<table id="brList"></table>
	
	<!-- 添加窗口 -->
	<div id="saveDiv" class="easyui-window" title="添加黑名单" style="padding:5px;width: 500px;height:400px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>

</body>
</html>